package com.yycwxt.modules.admin.dpyyfy_imp;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.yycwxt.common.BaseService;
import com.yycwxt.modules.admin.data_import.ImpFile;
import com.yycwxt.modules.admin.data_import.ImpFileMapper;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

@Service
@Transactional
public class DpyyfyService extends BaseService<ImpFileMapper, ImpFile>{
    private final DpyyfyMapper dpyyfyMapper;
    public DpyyfyService(DpyyfyMapper dpyyfyMapper){
        this.dpyyfyMapper=dpyyfyMapper;
    }

    @SneakyThrows
    @Transactional
    public void importDpyyfy(MultipartFile file) {
        EasyExcel.read(file.getInputStream(), Dpyyfy.class, new ReadListener<Dpyyfy>() {
            private static final int BATCH_SIZE = 1000;
            @Override
            public void invoke(Dpyyfy data, AnalysisContext context) {

                System.out.println(data);


                dpyyfyMapper.importDpyyfy(
                        data.getZq(),
                        data.getDpmc(),
                        data.getKmmc(),
                        data.getJe(),
                        data.getBz()
                );
            }

            @Override
            public void doAfterAllAnalysed(AnalysisContext context) {
            }
        }).sheet().doRead();
    }
}
